<?php

use yii\helpers\Html;
use yii\widgets\ActiveForm;
use dosamigos\datetimepicker\DateTimePicker;//时间
use common\models\projectaccounttype\ProjectAccounttype;
use yii\helpers\Arrayhelper;
use kartik\file\FileInput;

/* @var $this yii\web\View */
/* @var $model common\models\projectpaid\ProjectPaid */
/* @var $form yii\widgets\ActiveForm */
?>

<div class="project-paid-form">

    <?php $form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data']]); ?>

        <div>
        <div class="form-group field-classteam-time required" style="width: 300px">
            <label class="control-label" for="classteam-time">日期</label>
            <?= DateTimePicker::widget([
                'model' => $model,
                'attribute' => 'time',
                'language' => 'zh-CN',
                'size' => 'ms',
                'clientOptions' => [
                    'autoclose' => true,
                    'linkFormat' => 'yyyy-mm-dd  HH:ii ',
                    'todayBtn' => true
                ]
            ]);?>
        </div>
    </div>


    <?= $form->field($model, 'description')->textInput(['maxlength' => true]) ?>

    <?= $form->field($model, 'money')->textInput(['maxlength' => true]) ?>

    <?= $form->field($model, 'content')->textInput(['maxlength' => true]) ?>
        
        <?php
            if(isset(json_decode($model->attachment)->newname)){
                $img = json_decode($model->attachment)->newname;
            }else{

                $img = $model->attachment;
            }

            $siteRoot = Yii::$app->params['articlefile'];
            echo '<label class="control-label">上传附件</label>';
            echo FileInput::widget([
                'model' => $model,
                'attribute' => 'attachment',
                'options' => ['accept' => '*'],
                'pluginOptions' => [
                    'uploadExtraData' => [
                        'album_id' => 20,
                        'cat_id' => 'Nature'
                    ],
                    'initialPreview'=>[
                        !empty($img)?Html::img(Yii::$app->params['articlefile'].$img):null,
                    ],
                    'initialCaption'=> $img,
                    'maxFileCount' => 10,
                    "showUpload"=> false,
                ]
            ]);
        ?>
    

    <?= $form->field($model, 'account_type')->dropDownList(Arrayhelper::map(ProjectAccounttype::find()->asArray()->all(), 'id', 'name')) ?>

    <input type="hidden" name="ProjectPaid[category]" value="<?= $model->category; ?>">

    <div class="form-group">
        <?= Html::submitButton($model->isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
    </div>

    <?php ActiveForm::end(); ?>

</div>
